package com.itheima.user.sentinel.blockclasss;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@Component
public class UserSentinelControllerHanlder {


    /**
     * 限流后的返回
     *
     * @param a
     * @param b
     * @param e
     * @return
     */
    public static String hello66BlockHandler(@RequestParam(required = false) String a, @RequestParam(required = false) Integer b, BlockException e) {
        System.out.println("hello66BlockHandler " + e.getMessage());

        Map map = new HashMap();
        map.put("code", 429);
        map.put("message", "网络异常，请稍后尝试");

        return JSON.toJSONString(map);
    }


    /**
     * 限流后的返回
     *
     * @param e
     * @return
     */
    public static String hello7BlockHandler(int flag, BlockException e) {
        e.printStackTrace();

        Map map = new HashMap();
        map.put("code", 429);
        map.put("message", "网络异常，请稍后尝试 hello7BlockHandler");

        return JSON.toJSONString(map);
    }

}
